package com.seo.controller.proxy.keyWord;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.seo.function.PageTool;
import com.seo.service.keyword.proxy.sdk.ProxyKeywordGService;
import com.seo.service.keyword.sdk.KeywordGService;
import com.seo.utils.ClientConst;
import com.seo.utils.Jurisdiction;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: GoodsController
 * @author rtc
 * @version 2018.07.28 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "proxy/keyWordG/")
public class ProxyKeyWordGController {
	
	@Autowired
	private ProxyKeywordGService proxyKeywordGService;
	
	@Autowired
	private KeywordGService keywordGService;
	
	@Autowired
	private PageTool pageTool;

	/*
	 * 关键字列表
	 */
	@RequestMapping("/list")
	public String list(@RequestParam Map<String, Object> pam,HttpServletRequest request, HttpSession session) {
		log.info("进入关键字列表...");
		List<Map<String, Object>> venderList = proxyKeywordGService.getVenderList(); //厂商列表
		List<Map<String, Object>> engineList = keywordGService.getEngineList(); //搜索引擎列表
		Integer proxyUserId = Jurisdiction.getT("id", Integer.class, ClientConst.SESSION_PROXY_USER);
		Integer userId = Jurisdiction.getT("userId", Integer.class, ClientConst.SESSION_PROXY_USER);
		pam.put("parentId", userId); // 第三方用户 父级id
		pam.put("userId", proxyUserId); // 第三方用户id
		PageInfo<?> page = pageTool.getAutoPage(proxyKeywordGService::getKeyWordsList,pam);
		request.setAttribute("page", page);
		request.setAttribute("venderList", venderList);
		request.setAttribute("engineList", engineList);
		request.setAttribute("pam", pam);
		return "proxy/keyWord/keyWord_list";

	}
	
	/**
	 * 关键字审核列表
	 * @param params
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/reviewList")
	public String reviewList(@RequestParam Map<String, Object> pam,HttpServletRequest request, HttpSession session) {
		log.info("进入关键词审核列表...");
		log.info("获取页面的传值userName: " + pam.get("userName") + "typeValue：" + pam.get("typeValue"));
		List<Map<String, Object>> engineList = keywordGService.getEngineList(); //搜索引擎列表
		Integer proxyUserId = Jurisdiction.getT("id", Integer.class, ClientConst.SESSION_PROXY_USER);
		Integer userId = Jurisdiction.getT("userId", Integer.class, ClientConst.SESSION_PROXY_USER);
		pam.put("parentId", userId); // 第三方用户 父级id
		pam.put("userId", proxyUserId); // 第三方用户id
		PageInfo<?> page = pageTool.getAutoPage(proxyKeywordGService::getKeyWordsReviewList,pam);
		log.info("关键词审核列表查询的数据：" + page);
		request.setAttribute("page", page);
		request.setAttribute("pam", pam);
		request.setAttribute("engineList", engineList);
		return "proxy/keyWord/keyWord_review_list";

	}
}
